package me.dwk.dandan.function.functions;

import me.dwk.dandan.function.ThreadVariables;
import me.dwk.dandan.function.VariablesContext;

public class SimpleVariable {

	private String name;

	public SimpleVariable(String name) {
		this.name = name;
	}

	public SimpleVariable() {
		name = ""; //$NON-NLS-1$
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @see org.apache.jmeter.functions.Function#execute
	 */
	@Override
	public String toString() {
		String ret = null;
		ThreadVariables vars = getVariables();

		if (vars != null) {
			ret = vars.get(name);
		}

		if (ret == null)
			return "${" + name + "}";

		return ret;
	}

	private ThreadVariables getVariables() {
		return VariablesContext.getVariables();
	}

}
